package com.usian.admin.controller.v1;

import com.usian.admin.feign.WmNewsClient;
import com.usian.admin.service.AdWmNewsService;
import com.usian.apis.admin.AdWmNewsControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.dtos.WmNewsDto;
import com.usian.model.media.dtos.WmNewsFlia;
import com.usian.model.media.pojos.WmNews;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: AdWmNewsController
 * Author:   WGG
 * Date:    2022-11-2022/11/23-10:33
 * Version: 1.0
 * Description:
 */
@RestController
@RequestMapping("/admin/api/v1/news_auth")
public class AdWmNewsController implements AdWmNewsControllerApi {

  @Autowired
  private AdWmNewsService adWmNewsService;

  @Autowired
  private WmNewsClient wmNewsClient;

    @Override
    @PostMapping("/list")
    public ResponseResult listWmNews(@RequestBody WmNewsDto wmNewsDto) {
        return adWmNewsService.listWmNews(wmNewsDto);
    }

    @Override
    @GetMapping("/one/{id}")
    public ResponseResult one(@PathVariable Integer id) {
        return adWmNewsService.one(id);
    }



  @Override
  @GetMapping("/oneUpdate/{id}")
  public void oneUpdate(@PathVariable Integer id) throws Exception {
        adWmNewsService.oneUpdate(id);
  }

  @Override
  @PostMapping("/auth_pass")
  public ResponseResult authPass(@RequestBody WmNews wmNews) {
    return wmNewsClient.updateStatusAndReason(wmNews);
  }

  @Override
  @PostMapping("/auth_fail")
  public ResponseResult authFail(@RequestBody WmNewsFlia wmNewsFlia) {
    WmNews wmNews = new WmNews();
    wmNews.setStatus(wmNewsFlia.getStatus());
    wmNews.setId(wmNewsFlia.getId());
    wmNews.setReason(wmNewsFlia.getMsg());
    return wmNewsClient.updateStatusAndReason(wmNews);
  }

}
